import Field from "winged/utils/wt-model-field";
import gender from "winged/utils/wt-form-utils";

export default {
	title: "科室列表",
	customFormComponent: "wt-new-department",
	name: "departmentList",
	tableName: "departments",
	single: true,
	id_field: {
		tableName: "department_id"
	},
	query: {
		method: "DRONE",
		url: "uaa/user_info/get_all_department",
		extraParams: [],
		transfer: true,
		pagination: true,
		placeholder: "当前没有患者记录",
		sizeParam: "page_size",
		countParam: "count"
	},
	builder: function(data) {
		for (let i = 0; i < data.length; i++) {
			for (let e = 0; e < data.length; e++) {
				if (data[i].parent_id == data[e].department_id) {
					data[i].parent_name = data[e].name;
				}
			}
		}
		return data;
	},
	fields: [
		{
			label: "ID",
			type: Field.types.number,
			display: true,
			noFormDisplay: true,
			noSave: true,
			summary: true,
			name: "department_id",
			tableName: "department_id"
		},
		{
			label: "科室名",
			type: Field.types.text,
			display: true,
			name: "name",
			tableName: "name",
			rules: [
				{ required: true, message: "请选择上传头像", trigger: "blur" }
			]
		},
		{
			label: "科室等级",
			type: Field.types.select,
			display: true,
			name: "grade",
			tableName: "grader",
			rules: [
				{ required: true, message: "请选择科室等级", trigger: "blur" }
			],
			builder: function(data) {
				let grade;
				if (!data[this.tableName]) {
					switch (Number(data.grade)) {
						case 0:
							grade = "一级科室";
							break;
						case 1:
							grade = "二级科室";
							break;
						default:
							break;
					}
				}
				data[this.tableName] = grade;
			},
			options: [
				{
					label: "一级科室",
					value: "0"
				},
				{
					label: "二级科室",
					value: "1"
				}
			]
		},
		{
			label: "父级科室",
			type: Field.types.select,
			display: true,
			name: "parent_id",
			tableName: "parent_name",
			rules: [
				{
					type: "number",
					required: true,
					message: "身份证号码",
					trigger: "change"
				}
			],
			dependingField: {
				name: "grader",
				message: "请先选择科室等级",
				paramName: "grade"
			},
			builder: function(data) {
				if (!data[this.tableName]) {
					data[this.tableName] = "无";
				}
			},
			query: {
				url: "uaa/user_info/get_department_list",
				method: "DRONE",
				transfer: true,
				extraParams: ["parent_id", "page_index", "page_size"],
				label: "name",
				value: "department_id",
				resultParam: "departments"
			}
		}
	]
};
